/*
 * 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙，邂逅框架梦]
 * 
 * https://zhiqim.org/project/zhiqim_framework/zhiqim_helloworld.htm
 *
 * Zhiqim Helloworld is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *          http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */
package org.zhiqim.example;

import org.zhiqim.kernel.Servicer;
import org.zhiqim.kernel.logging.Log;
import org.zhiqim.kernel.logging.LogFactory;

/**
 * HelloWorld服务
 *
 * @version v1.0.0 @author zouzhigang 2016-12-21 新建与整理
 */
public class Helloworld extends Servicer implements Runnable
{
    private static final Log log = LogFactory.getLog(Helloworld.class);
    private Thread thread;
    
    @Override
    public boolean create() throws Exception
    {
        log.info("Hello， World！ create！！！");
        
        thread = new Thread(this);
        thread.start();
        return true;
    }

    @Override
    public void run()
    {
        while (true)
        {
            log.info("Hello， World！ running...");
            
            try
            {
                Thread.sleep(1000);
            }
            catch (InterruptedException e)
            {//线程中断退出
                break;
            }
        }
    }
    
    @Override
    public void destroy() throws Exception
    {
        log.info("Hello， World！ destroy！！！");
        
        //通知线程状态
        thread.interrupt();
        thread = null;
        
        //关闭前停5秒，演示关闭时销毁操作
        log.info("5");
        Thread.sleep(1000);
        log.info("4");
        Thread.sleep(1000);
        log.info("3");
        Thread.sleep(1000);
        log.info("2");
        Thread.sleep(1000);
        log.info("1");
        Thread.sleep(1000);
    }
}
